/**
 * 退出确认对话框
 */
package com.key.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.key.KeyChineseChessActivity;
import com.key.R;
import com.key.util.GameParams;

public class KeyExitDialog extends Dialog {

	private ImageButton OkButton;//确定按钮
	private ImageButton cancleButton;//取消按钮
	
	Activity contextAct;
	public KeyExitDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
		contextAct = (Activity)context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.key_exitdialog);
		OkButton =(ImageButton)findViewById(R.id.exitdialog_button_ok);
		OkButton.setOnClickListener(new View.OnClickListener(){
			public void onClick(View v) {
				//确定
				dismiss();
				((KeyChineseChessActivity)contextAct).initContants();//退出初始化游戏静态变量
				contextAct.finish();
			}
		});
		//背景切换
		OkButton.setOnTouchListener(new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == MotionEvent.ACTION_DOWN){
					((ImageButton)v).setBackgroundDrawable(contextAct.getResources().getDrawable(R.drawable.sure_down_btn));                         
                }else if(event.getAction() == MotionEvent.ACTION_UP){     
                	((ImageButton)v).setBackgroundDrawable(contextAct.getResources().getDrawable(R.drawable.sure_up_btn));
                }
                return false;     
            }
		});	
		
		cancleButton =(ImageButton)findViewById(R.id.exitdialog_button_cancle);
		cancleButton.setOnClickListener(new View.OnClickListener(){
			public void onClick(View v) {
				//取消
				cancel();
				//caculateGiveChess();
			}
		});
		//背景切换
		cancleButton.setOnTouchListener(new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == MotionEvent.ACTION_DOWN){
					((ImageButton)v).setBackgroundDrawable(contextAct.getResources().getDrawable(R.drawable.cancel_down_btn));                         
                }else if(event.getAction() == MotionEvent.ACTION_UP){     
                	((ImageButton)v).setBackgroundDrawable(contextAct.getResources().getDrawable(R.drawable.cancel_up_btn));
                }
                return false;     
            }
		});	
	}

}
